import pygame,pygame.locals
import sys,os,time


COLOR_BLACK = (0,0,0)
COLOR_WHITE = (255,255,255)
COLOR_GREEN = (0,255,0)
#COLOR_BKG = COLOR_BLACK

def game_init():
    pygame.init()
    pygame.display.init()

WINDOW_MAX_X = 400
WINDOW_MAX_Y = 400
DISPLAYSURFACE = pygame.display.set_mode((WINDOW_MAX_X,WINDOW_MAX_Y))
DISPLAYSURFACE.fill(COLOR_WHITE)    #   pygame的背景颜色
DISPLAYSURFACE_RECT = DISPLAYSURFACE.get_rect(center=(WINDOW_MAX_X/2,WINDOW_MAX_Y/2))   #   [0]

COLOR_BLOCK_X = 40
COLOR_BLOCK_Y = 40
COLOR_BLOCK_1_POSITION = (200,200)
COLOR_BLOCK_1 = pygame.Surface((COLOR_BLOCK_X,COLOR_BLOCK_Y))
COLOR_BLOCK_1.fill(COLOR_GREEN)
COLOR_BLOCK_1_RECT = COLOR_BLOCK_1.get_rect(center=COLOR_BLOCK_1_POSITION)

def COLOR_BLOCK_Move():
    DISPLAYSURFACE.blit(COLOR_BLOCK_1,COLOR_BLOCK_1_RECT)

    COLOR_BLOCK_1_RECT.move_ip(-5,0)
    print('COLOR_BLOCK_1_RECT.top = ',COLOR_BLOCK_1_RECT.top)
    if COLOR_BLOCK_1_RECT.right < 0 :
        COLOR_BLOCK_1_RECT.left = WINDOW_MAX_X
    else :
        pass

if __name__ == "__main__":
    game_init()
    FPS = 60
    while True:
        pygame.time.Clock().tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT:
                pygame.quit()
                sys.exit()

        DISPLAYSURFACE.blit(DISPLAYSURFACE,DISPLAYSURFACE_RECT)
        DISPLAYSURFACE_RECT.move_ip(0,1)
        print('DISPLAYSURFACE_RECT.top = ',DISPLAYSURFACE_RECT.top)
        if DISPLAYSURFACE_RECT.top > WINDOW_MAX_Y :
            DISPLAYSURFACE_RECT.top = 0
        COLOR_BLOCK_Move()

        pygame.display.update()